package com.demo.modules.mq.rabbit.service.direct;

import com.demo.modules.mq.rabbit.RabbitAnnouncementMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;


/**
 * 消息消费者
 *
 * @author Rog
 */
@Component
@Slf4j
public class RabbitDirectMessageConsumerService {
    /**
     * direct交换机模式下的接收
     *
     * @param rabbitAnnouncementMessage
     */
    @RabbitListener(queues = "direct.queue05")
    public void directQueueMq1(RabbitAnnouncementMessage rabbitAnnouncementMessage) {
        log.info("directQueueMq1" + "接收到的消息为{}", rabbitAnnouncementMessage);
    }

    /**
     * direct交换机模式下的接收
     *
     * @param rabbitAnnouncementMessage
     */
    @RabbitListener(queues = "direct.queue06")
    public void directQueueMq2(RabbitAnnouncementMessage rabbitAnnouncementMessage) {
        log.info("directQueueMq2" + "接收到的消息为{}", rabbitAnnouncementMessage);
    }

    /**
     * direct交换机模式下的接收(基于注解模式进行接收)
     *
     * @param rabbitAnnouncementMessage
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "direct.queue05", durable = "true"),
            exchange = @Exchange(name = "wr.direct", type = ExchangeTypes.DIRECT), //交换机类型type，有枚举类可供选择，这里一般都会有默认值
            key = {"info", "error"}//direct交换机key，数组类型，可以声明多个key
    ))
    public void directNewQueueMq1(RabbitAnnouncementMessage rabbitAnnouncementMessage) {
        log.info("directNewQueueMq1" + "接收到的消息为{}", rabbitAnnouncementMessage);
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "direct.queue06", durable = "true"),
            exchange = @Exchange(name = "wr.direct", type = ExchangeTypes.DIRECT), //交换机类型type，有枚举类可供选择，这里一般都会有默认值
            key = {"info", "error"}//direct交换机key，数组类型，可以声明多个key
    ))
    public void directNewQueueMq2(RabbitAnnouncementMessage rabbitAnnouncementMessage) {
        log.info("directNewQueueMq2" + "接收到的消息为{}", rabbitAnnouncementMessage);
    }
}
